import Vue from "vue";
import VueRouter from "vue-router";

const { match, push, replace } = VueRouter.prototype;

Object.assign(VueRouter.prototype, {
    match(location, ...args) {
        if (typeof location === "string" && location.substr(0, 1) !== "/") location = { name: location };
        return match.call(this, location, ...args);
    },
    push(location, ...args) {
        if (typeof location === "string" && location.substr(0, 1) !== "/") location = { name: location };
        return push.call(this, location, ...args).catch((error) => { });
    },
    replace(location, ...args) {
        if (typeof location === "string" && location.substr(0, 1) !== "/") location = { name: location };
        return replace.call(this, location, ...args).catch((error) => { });
    },
    title(location) {
        let route = this.match(location);
        return route && !route.redirectedFrom ? route.meta.title : "";
    },
});

Vue.use(VueRouter);